package com.ea.modular.service.sys;


import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ea.common.Constants.UserConstants;
import com.ea.common.parent.service.CrudService;
import com.ea.modular.dao.sys.UserDao;
import com.ea.modular.model.sys.User;

/**
 * 用户接口逻辑实现类
 * @author jun
 *
 */
@Service
@Transactional(readOnly=true)
public class UserService extends CrudService<UserDao,User> {

	@Autowired
	UserDao userDao;
	/**
	 * 密码加密加盐
	 * @param credentials
	 * @param salt
	 * @return
	 */
	public String passwordEncoder(String credentials, String salt) {
		Object object = new SimpleHash("MD5", credentials, salt, UserConstants.HASH_ITERATIONS);
		return object.toString();
	}
	
	/**
	 * 修改默认密码为111111
	 * @param id
	 * @param password
	 * @return
	 */
	@Transactional(readOnly=false)
	public int changePwd(String id,String password) {
		return userDao.changePwd(id,password);
	}
	
	/**
	 * 更改用户冻结状态
	 * @param id
	 * @return
	 */
	@Transactional(readOnly=false)
	public int freeze(String id,String flag){
		return userDao.freeze(id,flag);
	}
	
	/**
	 * 更改个人信息
	 * @param user
	 * @return
	 */
	@Transactional(readOnly=false)
	public int updateInfo(User user) {
		return userDao.updateInfo(user);
	}
}
